package com.wondertek.poms.bc.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.wondertek.poms.bc.manager.StartProcess;
import com.wondertek.poms.bc.vo.OutSourceDataParamsVo;
import com.wondertek.poms.common.controller.BaseController;
import com.wondertek.poms.common.utils.validate.ValidateFilter;
import com.wondertek.poms.common.vo.ResultBean;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
public class BcController extends BaseController {
	@Autowired
	StartProcess startProcess;

	/**
	 * <p><b>Title:</b> syncDistribute</p>
	 * <p><b>Description:</b> 播控主流程入口</p>
	 * @author douzi
	 * @param paramVo
	 * @return
	 */
	@PostMapping("/sync/distribute")
    public ResultBean syncDistribute(@RequestBody OutSourceDataParamsVo paramVo){
		log.info("数据准备|【批价传入参数】:|{}|接收成功", JSON.toJSONString(paramVo));
		// 验证批价给的数据是否合法
		String msg = verifyOutData(paramVo);
		if (null != msg) {
			return ResultBean.error(msg);
		}
		
		startProcess.fastProcess(paramVo);
        return ResultBean.ok();
	}
	
	/**
	 * <p><b>Title:</b> verifyOutData</p>
	 * <p><b>Description:</b> 验证批价给的数据是否合法</p>
	 * @author douzi
	 * @param sourceDataParamsVo
	 * @return
	 */
    public String verifyOutData(OutSourceDataParamsVo sourceDataParamsVo){
        List<String> messageList = ValidateFilter.getFilterMessage(sourceDataParamsVo);
        if (!messageList.isEmpty()) {
            log.info("验证批价传入数据不合法:" + messageList.toString());
            return messageList.toString();
        }
        return null;
    }
}
